package com.shark;

import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @auther shark
 * @create 2024-08-13 0:00
 */
@SpringBootTest
public class RabbitMQTestSendDelayMessage
{
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public static final String EXCHANGE_DELAY = "exchange.delay.video";
    public static final String ROUTING_KEY_DELAY = "routing.key.delay.video";
    public static final String QUEUE_DELAY = "queue.delay.video";

    @Test
    public void testSendDelayMessage() {
        rabbitTemplate.convertAndSend(
                EXCHANGE_DELAY,
                ROUTING_KEY_DELAY,
                "测试基于插件的延迟消息 [" + new SimpleDateFormat("hh:mm:ss").format(new Date()) + "]",
                messageProcessor -> {

                    // 设置延迟时间：以毫秒为单位
                    messageProcessor.getMessageProperties().setHeader("x-delay", "10000");

                    return messageProcessor;
                });
    }
}
